<?

$params[sid] = $sid;
$params[action] = "sales";
$url = "$baseURL/?".encode_params($params);

if ($errorMsg) {
include_once('errorMsg.html');
}
if ($okMsg) {
include_once('okMsg.html');
}

if(!$details[start]) $details[start] = get_signup_date($id);
if(!$details[end]) $details[end] = date("Y-m-d");

$date = explode("-",$details[start]);
$syear = $date[0];
$smonth = $date[1];
$sday = $date[2];

$date = explode("-",$details[end]);
$eyear = $date[0];
$emonth = $date[1];
$eday = $date[2];


$data =  list_payment_history($id,'details_normal',$details);
$ref_plan=get_refered_sales_stats($id,$details);
$refunds = list_payment_history($id,'details_refund',$details);

?>
<table width="500" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><font class="text"><b>View Sales Reports</b></font></td>
  </tr>
</table>
<br> <?=translate('select_period');?>:
<TABLE border=0 class='bTable' cellspacing='0'>
<form action='<? echo $url; ?>' method='POST'>
	<tr>
		<th><?=translate('type');?></th>
		<th><?=translate('day');?></th>
		<th><?=translate('month');?></th>
		<th><?=translate('year');?></th>
	</tr>
	<tr>
		<td><?=translate('start_report_date');?></td>
		<td>
			<select name='sday'>
			<?
				$opt = "<option value=''></option>";
				for($i=1;$i<=31;$i++){
					if($i<10) $opt .= "<option value='0$i'>$i</option>";
					else $opt .= "<option value='$i'>$i</option>";
				}
				$newopt = str_replace("'$sday'","$sday selected",$opt);
				echo $newopt;
			?>
			</select>
		</td>
		<td>
			<select name='smonth'>
			<?
				$opt = "<option value=''></option>";
				for($i=1;$i<=12;$i++){
					$m = date ("F", mktime(0,0,0,$i,2,2000));
						if($i<10) $opt .= "<option value='0$i'>$m</option>";
						else $opt .= "<option value='$i'>$m</option>";
				}
				$newopt = str_replace("'$smonth'","$smonth selected",$opt);
				echo $newopt;
			?>
			</select>
		</td>
		<td>
			<select name='syear'>
			<?
				$opt = "<option value=''></option>";
				for($i=2002;$i<=date("Y");$i++){
					if($i<10) $opt .= "<option value='0$i'>$i</option>";
					else $opt .= "<option value='$i'>$i</option>";

				}
				$newopt = str_replace("'$syear'","$syear selected",$opt);
				echo $newopt;
			?>
			</select>
		</td>
	</tr>
	<tr>
		<td><?=translate('end_report_date');?></td>

		<td>
			<select name='eday'>
			<?
				$opt = "<option value=''></option>";
				for($i=1;$i<=31;$i++){
					if($i<10) $opt .= "<option value='0$i'>$i</option>";
					else $opt .= "<option value='$i'>$i</option>";
				}
				$newopt = str_replace("'$eday'","$eday selected",$opt);
				echo $newopt;
			?>
			</select>
		</td>
		<td>
			<select name='emonth'>
			<?
				$opt = "<option value=''></option>";
				for($i=1;$i<=12;$i++){
					$m = date ("F", mktime(0,0,0,$i,2,2000));
						if($i<10) $opt .= "<option value='0$i'>$m</option>";
						else $opt .= "<option value='$i'>$m</option>";
				}
				$newopt = str_replace("'$emonth'","$emonth selected",$opt);
				echo $newopt;
			?>
			</select>
		</td>
		<td>
			<select name='eyear'>
			<?
				$opt = "<option value=''></option>";
				for($i=2003;$i<=date("Y");$i++){
					if($i<10) $opt .= "<option value='0$i'>$i</option>";
					else $opt .= "<option value='$i'>$i</option>";

				}
				$newopt = str_replace("'$eyear'","$eyear selected",$opt);
				echo $newopt;
			?>
			</select>
		</td>

	</tr>
	<tr>
		<td colspan='5' align='center'>
			<input type='submit' value='<?=translate('view_report');?>'>
		</td>
	</tr>
</form>
</TABLE>

<br>
<TABLE border=0 class='bTable' cellspacing='0'>

<tr>
	<th><?=translate('product');?></th>
	<th><?=translate('units');?></th>
	<th><?=translate('retail');?></th>
	<th><?=translate('wholesale');?></th>
	<th><?=translate('commission');?></th>
</tr>
<tr>
	<td><?=translate('dom_reg');?></td>
	<td><? echo ($data[domain][count])?$data[domain][count]:0; ?></td>
	<td>$<? echo ($data[domain][price])?$data[domain][price]:0; ?></td>
	<td>$<? echo ($data[domain][real_price])?$data[domain][real_price]:0; ?></td>
	<td>$<? echo ($data[domain][profit])?$data[domain][profit]:0; ?></td>
</tr>
<tr>
	<td><?=translate('hosting_sales');?></td>
	<td><? echo ($data[plan][count])?$data[plan][count]:0; ?></td>
	<td>$<? echo ($data[plan][price])?$data[plan][price]:0; ?></td>
	<td>$<? echo ($data[plan][real_price])?$data[plan][real_price]:0; ?></td>
	<td>$<? echo ($data[plan][profit])?$data[plan][profit]:0; ?></td>
</tr>
<tr>
        <td><?=translate('hosting_upgrade');?></td>
        <td><? echo ($data[upgrade][count])?$data[upgrade][count]:0; ?></td>
        <td>$<? echo ($data[upgrade][price])?$data[upgrade][price]:0; ?></td>
        <td>$<? echo ($data[upgrade][real_price])?$data[upgrade][real_price]:0; ?></td>
        <td>$<? echo ($data[upgrade][profit])?$data[upgrade][profit]:0; ?></td>
</tr>
<tr>
        <td><?=translate('hosting_renew');?></td>
        <td><? echo ($data[renewal][count])?$data[renewal][count]:0; ?></td>
        <td>$<? echo ($data[renewal][price])?$data[renewal][price]:0; ?></td>
        <td>$<? echo ($data[renewal][real_price])?$data[renewal][real_price]:0; ?></td>
        <td>$<? echo ($data[renewal][profit])?$data[renewal][profit]:0; ?></td>
</tr>
<tr>
	<td><?=translate('aff_plan_sale');?></td>
        <td><? echo ($ref_plan[count])?$ref_plan[count]:0; ?></td>
        <td>$<? echo ($ref_plan[price])?$ref_plan[price]:0; ?></td>
        <td>$<? echo ($ref_plan[real_price])?$ref_plan[real_price]:0; ?></td>
        <td>$<? echo ($ref_plan[profit])?$ref_plan[profit]:0; ?></td>
</tr>
<tr>
        <td><?=translate('dom_refunds');?></td>
        <td colspan='5'><? echo ($refunds[domain][count])?$refunds[domain][count]:0; ?></td>
</tr>
<tr>

    <td><?=translate('hosting_refunds');?></td>
        <td colspan='5'><? echo ($refunds[plan][count])?$refunds[plan][count]:0; ?></td>
</tr>
<tr>

    <td><?=translate('hosting_up_refunds');?></td>
        <td colspan='5'><? echo ($refunds[upgrade][count])?$refunds[upgrade][count]:0; ?></td>
</tr>
<tr>
        <td><?=translate('dom_charge_back');?></td>
        <td colspan='5'><? echo ($chargebacks[domain][count])?$chargebacks[domain][count]:0; ?></td>
</tr>
<tr>

    <td><?=translate('hosting_charge_back');?></td>
        <td colspan='5'><? echo ($chargebacks[plan][count])?$chargebacks[plan][count]:0; ?></td>
</tr>
<tr>

    <td><?=translate('hosting_up_charge_b');?></td>
        <td colspan='5'><? echo ($chargebacks[upgrade][count])?$chargebacks[upgrade][count]:0; ?></td>
</tr>


<tr>
	<td> <b><?=translate('total_comis');?></b>: </td>
	<td colspan='5'> <b>$
      <? echo sprintf("%01.2f",($data[domain][profit]+$data[plan][profit]+$data[upgrade][profit]+$data[renewal][profit]+$ref_plan[profit])); ?>
      </b> </td>
</tr>
</TABLE>


